class Solution 
{
public:
    vector<vector<int>> levelOrder(TreeNode* root) 
    {
        queue<TreeNode*> q;
        vector<vector<int>> vv;
        int levelSize=0;
        if(root)
        {
            q.push(root);
            levelSize=1;
        }

        while(!q.empty())
        {
            vector<int> v;
            for(int i=0;i<levelSize;++i)
            {
                TreeNode* front=q.front();
                q.pop();

                v.push_back(front->val);

                if(front->left) q.push(front->left);
                if(front->right) q.push(front->right);
            }
            vv.push_back(v);
            levelSize=q.size();
        }
        return vv;
    }
};